import cv2
import numpy as np

def get_hsv_color_range(image_path):
    # 读取图片
    image = cv2.imread(image_path)
    
    if image is None:
        print("Failed to read the image.")
        return
    
    # 将图片转换为 HSV 颜色空间
    hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    
    # 计算 HSV 颜色空间中的最小值和最大值
    h_min, s_min, v_min = np.min(hsv_image, axis=(0, 1))
    h_max, s_max, v_max = np.max(hsv_image, axis=(0, 1))
    
    return (h_min, s_min, v_min), (h_max, s_max, v_max)

# 指定PNG图片路径
image_path = "/home/chf/python_obj/KBD/test2.png"

# 获取 HSV 颜色范围
hsv_min, hsv_max = get_hsv_color_range(image_path)
print("HSV Color Range:")
print("Min: ", hsv_min)
print("Max: ", hsv_max)

"""
background_colour.png
Min:  (0, 0, 229)
Max:  (174, 14, 241)

Min:  (45, 1, 230)
Max:  (60, 2, 239)

point_green.png
Min:  (59, 154, 202)
Max:  (60, 255, 228)

red
Min:  (0, 202, 107)
Max:  (179, 255, 246)

track_grey
Min:  (0, 2, 131)
Max:  (120, 18, 142)

track_red
Min:  (2, 185, 124)
Max:  (4, 255, 242)

track_white
Min:  (0, 0, 252)
Max:  (165, 10, 255)
"""